import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('../../../../../large_data/CV2/lesson/Day07/Moscow.jpeg',0)

hist,bins = np.histogram(img.flatten(),256,[0,256])
cdf = hist.cumsum()
cdf_normalized = cdf * hist.max()/ cdf.max()
plt.plot(cdf_normalized, color = 'r')
plt.hist(img.flatten(),256,[0,256], color = 'b')
plt.xlim([0,256])
plt.legend(('cdf','histogram'), loc = 'upper left')
plt.show()

equ = cv2.equalizeHist(img)

plt.subplot(221)
plt.imshow(img, 'gray')
plt.subplot(222)
plt.imshow(equ, 'gray')
plt.subplot(223)
plt.hist(img.ravel(),256,[0,256])
plt.subplot(224)
plt.hist(equ.ravel(),256,[0,256])
plt.show()
